package ooday04;

public class test {
    public static void main(String[] args) {
//        Dog o1=new Dog("小黑",2,"黑");
//        Animal o2=new Dog("小白",2,"白");
//        Swim o3=new Dog("大黄",3,"黄");
//        o1.lookhome();
//        o2.drink();
//        o3.swim();

//        Master master=new Master();
//        Dog dog=new Dog("小黑",2,"黑");
//        Chick chick=new Chick("小花",3,"花");
//        Fish fish=new Fish("小金",1,"金");
//        master.feed(dog);
//        master.feed(chick);
//        master.feed(fish);

        Animal[] animals=new Animal[5];
        animals[0]=new Dog("小黑",2,"黑");
        animals[1]=new Chick("小花",3,"花");
        animals[2]=new Fish("小金",1,"金");
        animals[3]=new Fish("小草",1,"绿");
        animals[4]=new Dog("小白",1,"白");
        for (int i = 0; i < animals.length ; i++) {
            System.out.println(animals[i].name);
            animals[i].drink();
            animals[i].eat();

            if(animals[i] instanceof Dog){
                Dog dog=(Dog)animals[i];
                dog.lookhome();
            }
            if (animals[i] instanceof Chick){
                Chick chick=(Chick)animals[i];
                chick.layEggs();
            }
            if (animals[i] instanceof Swim){
                Swim s=(Swim) animals[i];
                s.swim();
            }
        }


//        Animal o2=new Dog("小白",2,"白");
//        Swim s=(Swim)o2;
//        Dog dog=(Dog)o2;
//        System.out.println(o2 instanceof Dog);
//        System.out.println(o2 instanceof Swim);
//        System.out.println(o2 instanceof Fish);
//        if (o2 instanceof Fish){
//            Fish f=(Fish)o2;
//        }else{
//            System.out.println("fish强转失败");
//        }
    }
}
